package metrics

type ProbeMetrics struct{}

func NewProbeMetrics() *ProbeMetrics {
	return &ProbeMetrics{}
}

func (ProbeMetrics) UpdateHttpMetrics(target string, statusCode float64, duration int64) {

	success_value := 0.0
	statusCode = float64(statusCode)
	if statusCode >= 200 && statusCode < 300 {
		success_value = 1.0
	}
	// 更新指标
	httpProbeDuration.Observe(duration, target)
	httpProbeStatusCode.Set(statusCode, target)
	httpProbeSuccess.Set(success_value, target)
}

func (ProbeMetrics) UpdateDnsMetrics(target string, success bool, duration int64) {
	// 获取成功率
	success_value := 0.0
	if success {
		success_value = 1.0
	}
	// 更新指标
	dnsProbeDuration.Observe(duration, target)
	dnsProbeSuccess.Set(success_value, target)
}

func (ProbeMetrics) UpdateTcpMetrics(target string, success bool, duration int64) {
	// 获取成功率
	success_value := 0.0
	if success {
		success_value = 1.0
	}
	// 获取成功率
	tcpProbeDuration.Observe(duration, target)
	tcpProbeSuccess.Set(success_value, target)
}
